package com.tnr.scgcxx.service.safty.impl;

import com.tnr.scgcxx.base.CurrUser;
import com.tnr.scgcxx.dao.safty.LoginDao;
import com.tnr.scgcxx.dto.UserDto;
import com.tnr.scgcxx.exception.BusinessException;
import com.tnr.scgcxx.exception.SysException;
import com.tnr.scgcxx.model.User;
import com.tnr.scgcxx.service.safty.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginDao loginDao;
    @Override
    public CurrUser checkLogin(UserDto dto) {

        User user;
        try {
            user=loginDao.findUserByIdAndPwd(dto);
        } catch (Exception e) {
           throw new SysException("系统错误！",e);
        }
        if (user==null){
            throw  new BusinessException("账号或密码错误");
        }
        return  new CurrUser(user.getU_id(),user.getU_name());

    }
}
